﻿//
using System.Collections;

// BingWallPaper, Copyright Mirosław M. Mączka.  All Rights Reserved. This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

namespace BingWallPaper
{
    public class ParseStyle
    {
        public static string GetUrl(string style, string name)
        {
            if (null == style) return "";
            Hashtable ht = new Hashtable();
            foreach (string s in style.Split(';'))
            {
                string[] ss = s.Split(new[] { ':' }, 2);
                if (2 != ss.Length) continue;
                ht.Add(ss[0].Trim().ToUpper(), ss[1].Trim());
            }
            //
            name = name.ToUpper();
            if (ht.ContainsKey(name))
            {
                string v = ht[name].ToString();
                if (v.StartsWith("url(\"")) v = v.Replace("url(\"", "");
                if (v.StartsWith("url(")) v = v.Replace("url(", "");
                if (v.EndsWith("\")")) v = v.Replace("\")", "");
                if (v.EndsWith(")")) v = v.Replace(")", "");
                return v.Trim();
            }
            return "";
        }
        /*
         * IE8 Ucase, IE9 Lcase
                        urlWallPaper = rs.Replace("url(\"", "").Replace("\")", "").Trim();//7-IE9
                        urlWallPaper = rs.Replace("url(", "").Replace(")", "").Trim();//XP-IE8
         */
    }
}
